package com.hazardSoft.eStore.entities;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import com.hazardSoft.eStore.utils.QueryConstants;

@Entity
@NamedQueries({
	@NamedQuery(name = QueryConstants.QUERY_LIST_SALES_BY_BILL, query = "FROM Sale sl WHERE sl.bill=?1"),
	@NamedQuery(name = QueryConstants.QUERY_SEARCH_SALE, query = "FROM Sale sl WHERE sl.product=?1 and sl.bill=?2")
})
public class Sale implements Serializable {
	@Id
//	@GeneratedValue
	private Integer id;

	private Integer quantity;

	private double cost;

	@ManyToOne
	@JoinColumn(name="product")
	private Product product;

	@ManyToOne
	@JoinColumn(name="bill")
	private Bill bill;

	private static final long serialVersionUID = 1L;

	public Sale() {
		super();
	}

	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public double getCost() {
		return this.cost;
	}

	public void setCost(double cost) {
		this.cost = cost;
	}

	public Product getProduct() {
		return this.product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}

	public Bill getBill() {
		return this.bill;
	}

	public void setBill(Bill bill) {
		this.bill = bill;
	}
	
	public boolean equals(Object object){
		if (object == null) {
			return false;
		}
		if (!(object instanceof Sale)) {
			return false;
		}
		Sale sale = (Sale) object;
		if (sale.getProduct() == null) {
			return false;
		}
		if (!(sale.getProduct().equals(this.getProduct()))) {
			return false;
		}
		return true;
	}

}
